<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>会员资料编辑-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../static/css/font.css">
    <link rel="stylesheet" href="../../static/css/weadmin.css">
    <script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="weadmin-body">
    <form class="layui-form" lay-filter="test">
        <div class="layui-form-item">
            <label for="oid" class="layui-form-label">
               社团ID
            </label>
            <div class="layui-input-inline">
                <input type="text" id="oid" name="oid" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
               物资名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="nums" class="layui-form-label">
               物资数量
            </label>
            <div class="layui-input-inline">
                <input type="text" id="nums" name="nums" required="" lay-verify=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="price" class="layui-form-label">
              物资价格
            </label>
            <div class="layui-input-inline">
                <input type="text" id="price" name="price" required="" lay-verify=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="tips" class="layui-form-label">
               物资简介
            </label>
            <div class="layui-input-inline">
                <textarea id="tips" name="tips" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="tips" class="layui-form-label"></label>
            <button  class="layui-btn" lay-filter="update" lay-submit="">修改</button>
        </div>
    </form>
</div>
<script src="../../lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">
    layui.extend({
        admin: '{/}../../static/js/admin'
    });

    var dataId;
    var oid;
    var name;
    var price;
    var tips;

    //获取上个窗口的参数
    function child(data){
        dataId = data.id;
        oid = data.oid;
        name = data.name;
        price = data.price;
        tips = data.tips;
    }

    layui.use(['form', 'jquery', 'admin','layer'], function() {
        var form = layui.form,
            $ = layui.jquery,
            admin = layui.admin,
            layer = layui.layer;
        var index = parent.layer.getFrameIndex(window.name);
        //页面初始化加载
        $(function(){
            setTimeout(function(){
                frameVal();
            },100);
        });
        function frameVal(){
            var index = parent.layer.getFrameIndex(window.name);
            form.val("test", {
                 "oid": oid
                ,"name":name
                ,"price":price
                ,"tips":tips
            });
        }

        //监听提交
        form.on('submit(update)', function(data) {
            //获取表单字段的value
            var f = data.field;
            // 获得frame索引
            var index = parent.layer.getFrameIndex(window.name);
            var d = {
                "id": dataId // "name": "value"
                    , "oid": f.oid
                    , "name":f.name
                    ,"title":f.title
                    ,"nums":f.nums
                    ,"tips":f.tips
                    ,"price":f.price
            };
            console.log(data);
            $.ajax({
                type: "post",
                url: '/api/organ/goods/UpdateGoods',
                contentType:'application/json;charset=UTF-8',
                data:JSON.stringify(d),
                success: function(res){
                    if(res.code ==0|| res.msg=="成功")
                        layer.alert("更新成功", {
                            icon: 6
                        }, function() {
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    else{
                        layer.alert("更新失败");
                    }
                }
            });
            return false;
        });


    });
</script>
</body>

</html>